package com.qing.common.executor

import android.os.Handler
import android.os.Looper
import com.google.common.util.concurrent.ListenableFuture
import com.qing.common.base.BaseExecutor
import java.util.concurrent.Callable

private const val TAG = "DefaultMainExecutor"

class DefaultMainExecutor : BaseExecutor {

    private val mMainExecutor by lazy {
        Handler(Looper.getMainLooper())
    }

    override fun executeDelayed(command: Runnable, delay: Long) {
        postDelayed(command, delay)
    }

    override fun <T> listenerExecute(command: Callable<T>): ListenableFuture<T> {
        TODO("main executor should not be implemented")
    }

    override fun post(command: Runnable) {
        postDelayed(command, 0)
    }

    override fun postDelayed(command: Runnable, delay: Long) {
        mMainExecutor.postDelayed(command, delay)
    }

    override fun execute(command: Runnable) {
        post(command)
    }

    override fun close() {
        // do nothing
    }
}